package com.atguigu.gmall.realtime.bean;

import lombok.*;
import org.springframework.cglib.beans.BeanCopier;

import java.math.BigDecimal;

/**
 * 支付宽表
 *
 * @author lvbingbing
 * @date 2022-06-29 16:14
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class PaymentWide {

    /*-------------------- 1。支付信息 --------------------*/

    /**
     * 支付信息主键
     */
    private Long payment_id;

    /**
     * 商品信息
     */
    private String subject;

    /**
     * 支付方式
     */
    private String payment_type;

    /**
     * 支付单创建时间
     */
    private String payment_create_time;

    /**
     * 支付回调时间
     */
    private String callback_time;

    /**
     * 总金额
     */
    private BigDecimal total_amount;

    /*-------------------- 2。订单宽表信息 --------------------*/

    /**
     * 订单详情表id
     */
    private Long detail_id;

    /**
     * 订单id
     */
    private Long order_id;

    /**
     * 商品id
     */
    private Long sku_id;

    /**
     * 购买价格(下单时sku价格）
     */
    private BigDecimal order_price;

    /**
     * 购买数量
     */
    private Long sku_num;

    /**
     * sku名称（冗余)
     */
    private String sku_name;

    /**
     * 地区
     */
    private Long province_id;

    /**
     * 订单状态
     */
    private String order_status;

    /**
     * 用户id
     */
    private Long user_id;

    /**
     * 促销金额
     */
    private BigDecimal activity_reduce_amount;

    /**
     * 优惠券
     */
    private BigDecimal coupon_reduce_amount;

    /**
     * 原价金额
     */
    private BigDecimal original_total_amount;

    /**
     * 运费
     */
    private BigDecimal feight_fee;

    private BigDecimal split_feight_fee;

    private BigDecimal split_activity_amount;

    private BigDecimal split_coupon_amount;

    private BigDecimal split_total_amount;

    /**
     * 订单创建时间
     */
    private String order_create_time;

    private String province_name;

    private String province_area_code;

    private String province_iso_code;

    private String province_3166_2_code;

    private Integer user_age;

    private String user_gender;

    private Long spu_id;

    private Long tm_id;

    private Long category3_id;

    private String spu_name;

    private String tm_name;

    private String category3_name;

    public PaymentWide(PaymentInfo paymentInfo, OrderWide orderWide) {
        mergeOrderWide(orderWide);
        mergePaymentInfo(paymentInfo);
    }

    public void mergePaymentInfo(PaymentInfo paymentInfo) {
        if (paymentInfo != null) {
            BeanCopier beanCopier = BeanCopier.create(PaymentInfo.class, PaymentWide.class, false);
            beanCopier.copy(paymentInfo, this, null);
            payment_create_time = paymentInfo.getCreate_time();
            payment_id = paymentInfo.getId();
        }
    }

    public void mergeOrderWide(OrderWide orderWide) {
        if (orderWide != null) {
            BeanCopier beanCopier = BeanCopier.create(OrderWide.class, PaymentWide.class, false);
            beanCopier.copy(orderWide, this, null);
            order_create_time = orderWide.getCreate_time();
        }
    }
}
